package com.sq.partner.manager.service.impl;

import com.sq.partner.manager.dao.CtripDao;
import com.sq.partner.manager.service.CtripService;
import com.sq.partner.manager.util.Page;
import com.sq.partner.manager.util.excel.ExcelEntity;
import com.sq.partner.manager.util.excel.ExportExcelBuilderTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Service
public class CtripServiceImpl implements CtripService {

    @Autowired
    private CtripDao ctripDao;

    @Autowired
    ExportExcelBuilderTool exportExcelBuilderTool;


    @Override
    public Page queryStatisticsPage(Page page) throws Exception{
        return ctripDao.queryStatisticsPage(page);
    }

    @Override
    public Page queryPolicyPageByEffecttime(Page page) throws Exception {
        return ctripDao.queryPolicyPageByEffecttime(page);
    }

    @Override
    public void downloadExcel(List ctripList, HttpServletResponse response) throws Exception {
        ExcelEntity excel = new ExcelEntity();
        excel.setResults(ctripList);
        excel.setFileName("ctripPolicyInfo");
        excel.setTitles("产品代码,单号,状态,保费,被保人姓名,被保人证件号码,生效时间,失效时间,交易时间,佣金");
        excel.setTitleKeys("PRODUCTCODE,POLICYNO,INSURANCETYPE,PREMIUM,INSUREDNAME,INSUREDCARDNO,EFFECTTIME,EXPIRYTIME,TRANSTIME,COMMISSION");
        excel.setColumns("30,50,20,20,20,50,30,30,30,20");

        exportExcelBuilderTool.buildExcel(response,excel);
    }

    @Override
    public List<Map<String, Object>> queryAllPolicyByEffecttime(Page page) throws Exception{
        return ctripDao.queryAllPolicyByEffecttime(page);
    }
}
